package com.neusoft.common.util;

import java.io.*;

/**
 * 字符集转换
 * Created By YZ at Jun 30, 2010 11:27:59 AM
 * Class:EncodingConvert
 *
 */
public class EncodingConvert{
    public static String convertTo8859_1(String str){
        if(str == null)
            return "";
        try{
            return new String(str.trim().getBytes("ISO-8859-1"));
        } catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return "";
    }

    public static String convertToGBK(String str){
        if(str == null)
            return "";
        try{
            return new String(str.trim().getBytes("GBK"), "ISO-8859-1");
        } catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return "";
    }

    public static Object[] convertToGBK(Object[] args){
        for(int i = 0; i < args.length; i++){
            if(String.class.isInstance(args[i])){
                args[i] = EncodingConvert.convertToGBK(args[i].toString());
            }
        }
        return args;
    }

    public static Object convertToGBK(Object obj){
        if(String.class.isInstance(obj)){
            obj = EncodingConvert.convertToGBK(obj.toString());
        }
        return obj;
    }

    public static Object convertTo8859_1(Object obj){
        if(String.class.isInstance(obj)){
            obj = EncodingConvert.convertTo8859_1(obj.toString());
        }
        return obj;
    }
}
